﻿/*
* 此文件用于实现管理员的功能
*/
#define _CRT_SECURE_NO_WARNINGS
#include "basic.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "log.h"

extern const char* MANAGER_FILE;
//对函数进行声明
Ord* init_CusData();
void add_CustomerInfo(Ord* cusdata, Ord* new_ord);
void modify_CustomerInfo(Ord* cusdata, Ord* new_ord);
void delete_CustomerInfo(Ord* cusdata, Ord* new_ord);
void manage_BasicInfo();
void modify_Password();
void manage_BasicInfo();
void adjust_RoomType();
void changeCustomerType();
void changeRoomPrice();
void setCustomerDiscount();
void manage_setting();
void maintain_Password();

void display_Orders(Ord* cusdata);
void sort_Orders();
void read_Orders(Ord* cusdata);

//void sort_BySingleAttribute(Ord* cusdata, int attribute);
//void sort_ByMultipleAttributes(Ord* cusdata, int attribute1, int attribute2);

/*张善杰增加*/
float discount_rates[4] = { 1.0, 0.9, 0.8, 0.7 }; // 折扣率数组: 普通,VIP,白金,团体
/* 新增函数声明 - 信息设置管理相关 */
void manage_setting();
void adjust_RoomType();
void add_new_room();
void modify_existing_room();
void delete_room();
void display_room_list();
void changeRoomPrice();
void adjust_single_room_price();
void batch_adjust_room_price();
void setCustomerDiscount();
void display_current_discounts();
void update_discount_rate(int type_index);
/* 新增函数声明 - 统计功能相关 */
/*张善杰添加函数声明*/
// 统计功能函数声明
void data_statistics_menu();
void listEmptyRooms();
void calculateOccupancyRate();
void calculateRoomTypeOccupancy();
void single_attribute_statistics();
void multiple_attribute_statistics();
void preset_statistics();
void conditional_statistics();
/*新增*/
// 修改折扣率
void modify_discount_rate();
// 更新折扣率的函数（根据客户身份类型索引）
void update_discount_rate(int type_index);
////////////////////////////////////////////////
// 单一属性统计函数声明
void count_by_room_type();
void count_by_customer_name();
void count_by_room_price();


// 多属性统计函数声明
void count_by_room_type_and_customer_name();
void count_by_check_in_and_check_out_date(Ord* cusdata);

// 预设统计函数声明
void calculate_occupancy_rate_in_period();
void calculate_booking_rate_in_period();

// 按条件统计函数声明
void calculate_total_stay_days_for_customer();
void calculate_occupancy_and_booking_rate_in_period();

//信息查询
void manager_search_info();

//信息排序
void sort_ord_mana(Ord* cusdata);
void display_orders_sort_mana(Ord* cusdata);
void sort_By_SingleAttribute_mana(Ord* cusdata, int attribute);
void sort_By_MultipleAttributes_mana(Ord* cusdata, int attribute1, int attribute2);
void change_room_status_mana(int room_id, const char* new_status);
const char hotel_room[] = "D:\\Hotel\\Try1 - test1 - fix1_new\\room.txt";//文件路径自己修改
//初始化房间信息,并返回房间链表的头指针
Room* head = initialize_rooms(hotel_room);
Room* room_lists = head;

// 初始化链表头
const char* file_addr = "D:\\Hotel\\Try1 - test1 - fix1_new\\order.txt";
Ord* cusdata = initialize_guests(file_addr);

//用户退房
void check_out_mana()
{
	//办理退房
	printf("|||          欢迎来到退房界面             ||\n");
	printf("=============================================\n");
	printf("||		请输入顾客的订单号：              ||\n");
	int order_id;
	scanf("%d", &order_id);
	Ord* new_order = (Ord*)malloc(sizeof(Ord));
	//查找订单
	new_order = cusdata;
	while (new_order != NULL)
	{
		if (new_order->order_id == order_id)
		{
			break;
		}
		new_order = new_order->next;
	}
	if (new_order == NULL)
	{
		printf("未找到该订单！\n");
		return;
	}
	strcpy(new_order->order_state, "已退房");
	printf("退房成功！\n");
	//将房间状态改为可用
	change_room_status_mana(new_order->room_id, "空闲");
	//将退房信息写入文件
	FILE* fp = fopen(file_addr, "w");
	if (fp == NULL)
	{
		printf("无法打开文件\n");
		return;
	}
	Ord* temp = cusdata;
	while (temp != NULL)
	{
		fprintf(fp, "%d %d %s %d %s %s %s %s %s %s\n",
			temp->order_id, temp->room_id, temp->room_type, temp->room_price,
			temp->order_state, temp->customer_name, temp->customer_phone,
			temp->customer_identity, temp->start_time, temp->end_time);
		temp = temp->next;
	}
	fclose(fp);
}

//打印一个管理员的菜单
void menu_Manager()
{
	while (1)
	{
		printf("\n");
		printf("===============================================\n");
		printf("||                                           ||\n");
		printf("||          欢迎来到管理员控制台             ||\n");
		printf("||                                           ||\n");
		printf("===============================================\n");
		printf("||                                           ||\n");
		printf("||          请选择要执行的操作：             ||\n");
		printf("||                                           ||\n");
		printf("||              1. 管理员基本信息管理        ||\n");
		printf("||              2. 信息设置管理              ||\n");
		printf("||              3. 密码安全维护              ||\n");
		printf("||              4. 信息排序                  ||\n");
		printf("||              5. 信息统计                  ||\n");
		printf("||              6. 信息查询                  ||\n");
		printf("||              7. 用户退房管理              ||\n");
		printf("||              8. 客人订单显示              ||\n");
		printf("||              9. 房间信息显示              ||\n");
		printf("||              0. 退出登录                  ||\n");
		printf("||                                           ||\n");
		printf("===============================================\n");

		int choice;
		printf("\n>>> 请输入操作选项 (0-9): ");
		scanf("%d", &choice);
		switch (choice)
		{
		case 1:
			//管理员基本信息管理
			manage_BasicInfo();
			break;
		case 2:
			//信息设置管理
			manage_setting();
			break;
		case 3:
			//系统密码维护
			maintain_Password();
			break;
		case 4:
			//排序
			sort_ord_mana(cusdata);
			break;
		case 5:
			//数据统计与分析
			data_statistics_menu();
			break;
		case 6:
			//信息查询
			manager_search_info();
			break;
		case 7:
			//用户退房管理
			check_out_mana();
			break;
		case 8:
			//客人订单显示
			display_Orders(cusdata);
			break;
		case 9:
			//房间信息显示
			display_room_list();
			break;
		case 0:
			//退回到主界面
			Menu();
			break;
		default:
			printf("输入错误，请重新输入\n");
			menu_Manager();
		}
	}
}





// 读取文件数据并添加到链表

//调整不同类型用户的折扣
int judge_price(Ord* new_cus)
{
	//根据客户身份类型设置折扣
	if (strcmp(new_cus->customer_identity, "普通") == 0)
	{
		new_cus->room_price = new_cus->room_price * discount_rates[0];
		return 1;
	}
	else if (strcmp(new_cus->customer_identity, "VIP") == 0)
	{
		new_cus->room_price = new_cus->room_price * discount_rates[1];
		return 1;
	}
	else if (strcmp(new_cus->customer_identity, "白金") == 0)
	{
		new_cus->room_price = new_cus->room_price * discount_rates[2];
		return 1;
	}
	else if (strcmp(new_cus->customer_identity, "团体") == 0)
	{
		new_cus->room_price = new_cus->room_price * discount_rates[3];
		return 1;
	}
	else
	{
		printf("您填入的身份信息有误，请重新输入\n");
		return 0;
	}
}
//修改房间状态的函数
void change_room_status_mana(int room_id, const char* new_status)
{
	//在房间链表中找到对应的房间
	Room* room = room_lists;
	while (room != NULL)
	{
		if (room->room_id == room_id)
		{
			//修改房间状态
			strcpy(room->room_state, new_status);
			break;
		}
		room = room->next;
	}
	//将房间状态写入文件
	FILE* fp = fopen(hotel_room, "w");
	if (fp == NULL)
	{
		printf("无法打开文件\n");
		return;
	}
	Room* temp = room_lists;
	while (temp != NULL)
	{
		fprintf(fp, "%d %s %d %s\n", temp->room_id, temp->room_type, temp->room_price, temp->room_state);
		temp = temp->next;
	}
	fclose(fp);
	printf("房间状态已更新！\n");
}
//1.对于酒店的房间类型，客房，客人类型的基本信息进行管理(增删改查)
//增加客人的订单的基本信息
void add_CustomerInfo(Ord* cusdata)
{
	//1.添加客人到链表里面(这里用头插法),并且使用文件保存
	Ord* new_cus = (Ord*)malloc(sizeof(Ord));//申请一个新的客人
	//打开文件
	int lastOrderId = 1;
	//输入客人的基本信息
	//根据文件中最后一条记录的订单号来生成新的订单号
	if (cusdata == NULL)
	{
		lastOrderId = 1;
	}
	else
	{
		Ord* temp = cusdata;
		while (temp->next != NULL)
		{
			temp = temp->next;
		}
		lastOrderId = temp->order_id;
	}
	lastOrderId++;
	printf("请输入客人订购的房间号:");
	scanf("%d", &new_cus->room_id);
	printf("请输入客人订购的房间类型:");
	scanf("%s", new_cus->room_type);
	printf("请输入客人订购的房间价格:");
	scanf("%d", &new_cus->room_price);
	printf("请输入客人的订单状态:");
	scanf("%s", new_cus->order_state);
	printf("请输入客人的姓名:");
	scanf("%s", new_cus->customer_name);
	printf("请输入客人的电话:");
	scanf("%s", new_cus->customer_phone);
	printf("请输入客人的身份:(普通，VIP，白金，团体)");
	scanf("%s", new_cus->customer_identity);
	//将房间状态修改
	change_room_status_mana(new_cus->room_id, new_cus->order_state);
	//判断用户输入是否出错
	while (judge_price(new_cus) == 0)
	{
		printf("请重新输入客人的身份:(普通，VIP，白金，团体)");
		scanf("%s", new_cus->customer_identity);
		return;
	}
	printf("||    请输入客人的入住时间:    ||");
	printf("||    注意，入住时间格式为：YYYYMMDDHHMM    ||\n");
	scanf("%s", new_cus->start_time);
	printf("||    请输入客人的离开时间:    ||");
	printf("||    注意，离开时间格式为：YYYYMMDDHHMM    ||\n");
	scanf("%s", new_cus->end_time);
	new_cus->order_id = lastOrderId;
	// 将新的客人信息写入文件
	FILE* fp = fopen("D:\\Hotel\\Try1 - test1 - fix1_new\\order.txt", "a");
	if (fp == NULL)
	{
		printf("无法打开文件\n");
		return;
	}
	fprintf(fp, "%d %d %s %d %s %s %s %s %s %s\n",
		new_cus->order_id, new_cus->room_id, new_cus->room_type, new_cus->room_price,
		new_cus->order_state, new_cus->customer_name, new_cus->customer_phone, new_cus->customer_identity,
		new_cus->start_time, new_cus->end_time);
	printf("订单添加成功，订单号为: %d\n", new_cus->order_id);
	printf("请记住你的订单号，用于后续的操作\n");
	//关闭文件
	fclose(fp);
	new_cus->next = cusdata->next;//头插法
	cusdata->next = new_cus;
}

// 修改客户信息
void modify_CustomerInfo(Ord* cusdata)
{
	if (cusdata->next == NULL)
	{
		printf("客户数据为空\n");
		return;
	}

	int change_id;
	printf("请输入你要修改的订单号:");
	if (scanf("%d", &change_id) != 1)
	{
		printf("无效输入\n");
		return;
	}

	// 遍历链表查找订单
	Ord* current = cusdata;  // 假设头节点不存储数据
	Ord* target = NULL;

	while (current != NULL)
	{
		if (current->order_id == change_id)
		{
			target = current;
			break;
		}
		current = current->next;
	}

	if (target == NULL) {
		printf("没有找到订单号 %d\n", change_id);
		return;
	}

	// 修改信息（带输入验证）
	printf("当前房间号(%d)，请输入新房间号:", target->room_id);
	scanf("%d", &target->room_id);

	printf("当前房间类型(%s)，请输入新类型:", target->room_type);
	scanf("%19s", target->room_type);

	printf("当前价格(%d)，请输入新价格:", target->room_price);
	scanf("%d", &target->room_price);

	printf("当前状态(%s)，请输入新状态:", target->order_state);
	scanf("%19s", target->order_state);

	printf("当前姓名(%s)，请输入新姓名:", target->customer_name);
	scanf("%49s", target->customer_name);

	printf("当前电话(%s)，请输入新电话:", target->customer_phone);
	scanf("%14s", target->customer_phone);

	printf("当前确认入住时间(%s)，请输入新入住时间:", target->start_time);
	scanf("%s", target->start_time);
	printf("当前确认离开时间(%s)，请输入新离开时间:", target->end_time);
	scanf("%s", target->end_time);
	// 将修改后的信息写入文件
	FILE* fp = fopen("D:\\Hotel\\Try1 - test1 - fix1_new\\order.txt", "w");
	if (fp == NULL)
	{
		printf("无法打开文件\n");
		return;
	}
	Ord* current_node = cusdata;
	while (current_node != NULL) {
		fprintf(fp, "%d %d %s %d %s %s %s %s %s %S\n",
			current_node->order_id, current_node->room_id, current_node->room_type,
			current_node->room_price, current_node->order_state,
			current_node->customer_name, current_node->customer_phone, current_node->customer_identity,
			current_node->start_time, current_node->end_time);
		current_node = current_node->next;
	}
}

// 删除客户信息
void delete_CustomerInfo(Ord* cusdata)
{
	if (cusdata == NULL)
	{
		printf("客户数据为空\n");
		return;
	}
	int change_id;
	printf("请输入要删除的订单号:");
	if (scanf("%d", &change_id) != 1)
	{
		printf("无效输入\n");
		return;
	}

	// 链表操作(头节点也有数据)
	Ord* prev = cusdata;
	Ord* current = cusdata->next;
	int found = 0;
	while (current != NULL)
	{
		if (current->order_id == change_id)
		{
			prev->next = current->next;
			//将房间状态改为空闲
			change_room_status_mana(current->room_id, "空闲");
			free(current);
			found = 1;
			break;
		}
		else if (prev->order_id == change_id)
		{
			free(prev);
			cusdata = current;
			found = 1;
			break;
		}
		prev = current;
		current = current->next;
	}

	if (!found)
	{
		printf("没有找到订单号 %d\n", change_id);
		return;
	}
	//保存修改后的链表到文件
	FILE* fp = fopen("D:\\Hotel\\Try1 - test1 - fix1_new\\order.txt", "w");
	if (fp == NULL) {
		printf("无法打开文件\n");
		return;
	}
	Ord* current_node = cusdata;
	while (current_node != NULL) {
		fprintf(fp, "%d %d %s %d %s %s %s %s %s %s\n",
			current_node->order_id, current_node->room_id, current_node->room_type,
			current_node->room_price, current_node->order_state,
			current_node->customer_name, current_node->customer_phone, current_node->customer_identity,
			current_node->start_time, current_node->end_time);
		current_node = current_node->next;
	}
}
void display_Orders(Ord* cusdata)
{
	//遍历链表
	Ord* current = cusdata;
	printf("订单号\t房间号\t房间类型\t房间价格\t订单状态\t客户姓名\t客户电话\t客户身份\t入住时间\t离开时间\n");
	while (current != NULL) {
		printf("%d\t%d\t%s\t%d\t%s\t%s\t%s\t%s\t%s\t%s\n",
			current->order_id, current->room_id, current->room_type,
			current->room_price, current->order_state,
			current->customer_name, current->customer_phone, current->customer_identity,
			current->start_time, current->end_time);
		current = current->next;
	}
}

void manage_BasicInfo()
{
	//接收到用户的预订信息或者现场入住，添加客人基本信息以及对应客房
	//先读取文件中的订单信息
	while (1)
	{
		printf("===========================================\n");
		printf("||                                       ||\n");
		printf("||      欢迎来到管理员基本信息管理       ||\n");
		printf("||                                       ||\n");
		printf("===========================================\n");
		printf("||              基本功能菜单             ||\n");
		printf("||        1. 添加订单                    ||\n");
		printf("||        2. 修改订单                    ||\n");
		printf("||        3. 删除订单                    ||\n");
		printf("||        4. 显示所有订单                ||\n");
		printf("||        5. 显示所有房间                ||\n");
		printf("||        6. 房间管理                    ||\n");
		printf("||        0. 退出基本信息管理界面        ||\n");
		printf("=====================================\n");
		printf("\n>>> 请输入你的选择 (0-6) :");
		int choice;
		scanf("%d", &choice);
		switch (choice)
		{
		case 1:

			//添加订单
			add_CustomerInfo(cusdata);
			break;
		case 2:
			modify_CustomerInfo(cusdata);
			break;
		case 3:
			delete_CustomerInfo(cusdata);
			break;
		case 4:
			display_Orders(cusdata);
			break;
		case 5:
			display_room_list();
			break;
		case 6:
			adjust_RoomType();
			break;
		case 0:
			menu_Manager();
			break;
		}
	}
}



//管理员任务之系统维护功能
//1.对自己的密码进行维护
void maintain_Password()
{
	//1.打印个菜单告诉管理员可以干的事
	printf("=============================================\n");
	printf("||			欢迎来到管理员密码维护界面     ||\n");
	printf("=============================================\n");
	printf("||			  1. 修改密码(更换密码)        ||\n");
	printf("||			  2. 退出系统维护界面          ||\n");
	printf("=============================================\n");
	int choice;
	printf("\n>>> 请输入你的选择 (1-2) :");
	scanf("%d", &choice);
	switch (choice)
	{
	case 1:
		//修改密码功能
		modify_Password();
	case 2:
		//退出
		return;
	}
}

//密码维护功能
void modify_Password()
{
	printf("请输入你要修改密码的账户名:");
	char username[20];
	scanf("%s", username);
	char password[20];
	long position = 0; // 用于记录密码位置的变量
	FILE* file = fopen(MANAGER_FILE, "r+");
	if (file == NULL)
	{
		printf("无法打开文件\n");
		return;
	}
	User admin;
	int found = 0;
	while (fscanf(file, "%s %s", admin.name, admin.password) != EOF)
	{
		if (strcmp(admin.name, username) == 0)
		{
			strcpy(password, admin.password);
			found = 1;
			position = ftell(file) - strlen(admin.password); // 记录密码开始位置
			break;
		}
	}

	if (found)
	{
		printf("找到管理员账户: %s\n", admin.name);
		printf("请输入新的密码:");
		char newPassword[20];
		scanf("%s", newPassword);
		// 定位到当前管理员账号密码所在位置
		if (strcmp(admin.password, password) == 0)
		{
			fseek(file, position, SEEK_SET);// 定位到密码开始位置
			// 写入新密码
			fputs(newPassword, file);
		}
		printf("密码修改成功\n");
	}
	else
	{
		printf("未找到管理员账户: %s\n", username);
	}
	fclose(file);
	return;
}


//再版，管理员排序
 //排序功能菜单
void sort_ord_mana(Ord* cusdata)
{
	int choice;
	do {
		printf("\n=====================================\n");
		printf("||          排序功能菜单            ||\n");
		printf("=====================================\n");
		printf("|| 1. 按单一属性排序                ||\n");
		printf("|| 2. 按多属性排序                  ||\n");
		printf("|| 0. 返回上一级菜单                ||\n");
		printf("=====================================\n");
		printf("\n>>> 请选择操作 (0-2) : ");
		scanf("%d", &choice);
		switch (choice) {
		case 1: {
			int attribute;
			printf("请选择排序属性：\n");
			printf("1. 订单ID\n");
			printf("2. 房间号\n");
			printf("3. 房间价格\n");
			printf("4. 订单状态\n");
			printf("5. 客户姓名\n");
			scanf("%d", &attribute);
			sort_By_SingleAttribute_mana(cusdata, attribute);
			printf("排序完成，以下是排序后的订单信息：\n");
			display_orders_sort_mana(cusdata);
			break;
		}
		case 2: {
			int attribute1, attribute2;
			printf("请选择第一个排序属性：\n");
			printf("1. 订单ID\n");
			printf("2. 房间号\n");
			printf("3. 房间价格\n");
			printf("4. 订单状态\n");
			printf("5. 客户姓名\n");
			scanf("%d", &attribute1);
			printf("请选择第二个排序属性：\n");
			printf("1. 订单ID\n");
			printf("2. 房间号\n");
			printf("3. 房间价格\n");
			printf("4. 订单状态\n");
			printf("5. 客户姓名\n");
			scanf("%d", &attribute2);
			sort_By_MultipleAttributes_mana(cusdata, attribute1, attribute2);
			printf("排序完成，以下是排序后的订单信息：\n");
			display_orders_sort_mana(cusdata);
			break;
		}
		case 0:
			printf("返回上一级菜单。\n");
			//回到管理员菜单
			menu_Manager();
			break;
		default:
			printf("无效选择，请重新输入！\n");
		}
	} while (choice != 0);
}




void swapOrd_mana(Ord* a, Ord* b) {
	if (a != b) {
		Ord temp = *a;
		*a = *b;
		*b = temp;

		// 交换next指针
		temp.next = a->next;
		a->next = b->next;
		b->next = temp.next;
	}
}
//按单一属性排序
void sort_By_SingleAttribute_mana(Ord* cusdata, int attribute) {
	if (cusdata == NULL || cusdata->next == NULL) {
		return; // 链表为空或只有一个节点，无需排序
	}

	int swapped;
	Ord* ptr1;
	Ord* lptr = NULL; // 用于标记已排序部分的最后一个节点

	do {
		swapped = 0;
		ptr1 = cusdata;

		while (ptr1->next != lptr) { // 确保ptr1->next不为NULL
			int cmp = 0;

			// 根据选择的属性进行比较
			switch (attribute) {
			case 1: // 按订单ID排序
				cmp = ptr1->order_id > ptr1->next->order_id;
				break;
			case 2: // 按房间号排序
				cmp = ptr1->room_id > ptr1->next->room_id;
				break;
			case 3: // 按房间价格排序
				cmp = ptr1->room_price > ptr1->next->room_price;
				break;
			case 4: // 按订单状态排序
				cmp = strcmp(ptr1->order_state, ptr1->next->order_state) > 0;
				break;
			case 5: // 按客户姓名排序
				cmp = strcmp(ptr1->customer_name, ptr1->next->customer_name) > 0;
				break;
			}

			if (cmp) {
				swapOrd_mana(ptr1, ptr1->next);
				swapped = 1;
			}
			ptr1 = ptr1->next;
		}
		lptr = ptr1;
	} while (swapped);
}

//按照多属性排序
void sort_By_MultipleAttributes_mana(Ord* cusdata, int attribute1, int attribute2)
{
	if (cusdata == NULL || cusdata->next == NULL) {
		return; // 链表为空或只有一个节点，无需排序
	}
	int swapped;
	Ord* ptr1;
	Ord* lptr = NULL;
	do {
		swapped = 0;
		ptr1 = cusdata;
		while (ptr1->next != lptr) { // 确保ptr1->next不为NULL
			int cmp1 = 0, cmp2 = 0;
			// 根据选择的属性进行比较
			switch (attribute1) {
			case 1: // 按订单ID排序
				cmp1 = ptr1->order_id > ptr1->next->order_id;
				break;
			case 2: // 按房间号排序
				cmp1 = ptr1->room_id > ptr1->next->room_id;
				break;
			case 3: // 按房间价格排序
				cmp1 = ptr1->room_price > ptr1->next->room_price;
				break;
			}
			switch (attribute2) {
			case 1: // 按订单ID排序
				cmp2 = ptr1->order_id > ptr1->next->order_id;
				break;
			case 2: // 按房间号排序
				cmp2 = ptr1->room_id > ptr1->next->room_id;
				break;
			case 3: // 按房间价格排序
				cmp2 = ptr1->room_price > ptr1->next->room_price;
				break;
			}
			if (cmp1 || (!cmp1 && cmp2)) {
				swapOrd_mana(ptr1, ptr1->next);
				swapped = 1;
			}
			ptr1 = ptr1->next;
		}
		lptr = ptr1;
	} while (swapped);
}
// 显示订单信息
void display_orders_sort_mana(Ord* cusdata)
{
	Ord* current = cusdata;
	printf("订单号\t房间号\t房间类型\t房间价格\t订单状态\t客户姓名\t客户电话\t入住时间\t离开时间\n");
	while (current != NULL) {
		printf("%d\t%d\t%s\t%d\t%s\t%s\t%s\t%s\t%s\n",
			current->order_id, current->room_id, current->room_type,
			current->room_price, current->order_state,
			current->customer_name, current->customer_phone,
			current->start_time, current->end_time);
		current = current->next;
	}
}



/*管理员2功能 信息设置管理 张善杰部分*/
void manage_setting()
{
	int choice;
	do
	{
		printf("\n=====================================\n");
		printf("||          信息设置管理           ||\n");
		printf("=====================================\n");
		printf("|| 1. 房间类型管理                 ||\n");
		printf("|| 2. 房间价格管理                 ||\n");
		printf("|| 3. 客户折扣管理                 ||\n");
		printf("|| 0. 返回上级菜单                 ||\n");
		printf("=====================================\n");
		printf("\n>>> 请选择操作 (0-3) :");
		scanf("%d", &choice);

		switch (choice)
		{
		case 1:
			adjust_RoomType();
			break;
		case 2:
			changeRoomPrice();
			break;
		case 3:
			setCustomerDiscount();
			break;
		case 0:
			break;
		default:
			printf("无效选择!\n");
		}
	} while (choice != 0);
}

void adjust_RoomType()
{
	int choice;
	do
	{
		printf("\n=====================================\n");
		printf("||          房间类型管理           ||\n");
		printf("=====================================\n");
		printf("|| 1. 添加新房间类型               ||\n");
		printf("|| 2. 修改现有房间类型             ||\n");
		printf("|| 3. 删除房间类型                 ||\n");
		printf("|| 4. 查看所有房间类型             ||\n");
		printf("|| 0. 返回上级菜单                 ||\n");
		printf("=====================================\n");
		printf("\n>>> 请选择操作 (0-4) :");
		scanf("%d", &choice);
		switch (choice)
		{
		case 1:
			add_new_room();
			break;
		case 2:
			modify_existing_room();
			break;
		case 3:
			delete_room();
			break;
		case 4:
			display_room_list();
			break;
		case 0:
			break;
		default:
			printf("无效选择!\n");
		}
	} while (choice != 0);
}

void add_new_room()
{
	Room* new_room = (Room*)malloc(sizeof(Room));
	printf("请输入房间号: ");
	scanf("%d", &new_room->room_id);
	// 检查房间号是否已存在
	Room* current = room_lists;
	while (current != NULL)
	{
		if (current->room_id == new_room->room_id)
		{
			printf("房间号已存在，请重新输入\n");
			free(new_room);
			return;
		}
		current = current->next;
	}
	printf("请输入房间类型: ");
	scanf("%s", new_room->room_type);
	printf("请输入房间价格: ");
	scanf("%d", &new_room->room_price);
	strcpy(new_room->room_state, "空闲");
	new_room->next = room_lists;
	room_lists = new_room;
	// 将房间信息写入文件
	FILE* fp = fopen(hotel_room, "a");
	if (fp == NULL)
	{
		printf("无法打开文件\n");
		return;
	}
	fprintf(fp, "%d %s %d %s\n", new_room->room_id, new_room->room_type, new_room->room_price, new_room->room_state);
	fclose(fp);
	printf("房间添加成功！\n");
}

// 修改现有房间
void modify_existing_room()
{
	int room_id;
	printf("请输入要修改的房间号: ");
	scanf("%d", &room_id);
	Room* current = room_lists;
	int find = 0;
	while (find == 0 && current != NULL)
	{
		if (current->room_id == room_id)
		{
			find = 1;
			break;
		}
		else if (find == 0)
		{
			current = current->next;
		}

	}
	if (find == 0)
	{
		printf("没有找到该房间号的房间！\n");
		return;
	}
	printf("请输入新的房间类型：");
	scanf("%s", current->room_type);
	printf("请输入新的房间价格：");
	scanf("%d", &current->room_price);
	printf("请输入新的房间状态：");
	scanf("%s", current->room_state);

	if (find == 1)
	{
		// 将房间信息写入文件
		FILE* fp = fopen(hotel_room, "w");//将文件模式改为"w"，以覆盖原有内容，将所有房间信息重新写入文件
		if (fp == NULL)
		{
			printf("无法打开文件 \n");
			return;
		}
		// 遍历链表，将所有房间信息写入文件
		Room* temp = room_lists;
		while (temp != NULL)
		{
			fprintf(fp, "%d %s %d %s\n", temp->room_id, temp->room_type, temp->room_price, temp->room_state);
			temp = temp->next;
		}
		free(temp);
		// 关闭文件
		fclose(fp);
	}
}

// 删除房间
void delete_room()
{
	int room_id;
	printf("请输入要删除的房间号: ");
	scanf("%d", &room_id);
	Room* current = room_lists;
	Room* previous = NULL;
	while (current != NULL)
	{
		if (current->room_id == room_id)
		{
			if (previous == NULL)
			{
				room_lists = current->next;
			}
			else
			{
				previous->next = current->next;
			}
			free(current);
			printf("房间删除成功！\n");

			// 将房间信息写入文件
			FILE* fp = fopen(hotel_room, "w");
			if (fp == NULL)
			{
				printf("无法打开文件\n");
				return;
			}
			Room* temp = room_lists;
			while (temp != NULL)
			{
				fprintf(fp, "%d %s %d %s\n", temp->room_id, temp->room_type, temp->room_price, temp->room_state);
				temp = temp->next;
			}
			fclose(fp);
			return;
		}
		previous = current;
		current = current->next;
	}
	printf("未找到该房间号的房间！\n");
}

// 查看所有房间
void display_room_list()
{
	Room* current = room_lists;
	printf("所有房间信息如下:\n");
	printf("房间号\t类型\t价格\t状态\n");
	while (current != NULL)
	{
		printf("%d\t%s\t%d\t%s\n", current->room_id, current->room_type, current->room_price, current->room_state);
		current = current->next;
	}
}

// 房间价格管理
void changeRoomPrice()
{
	int choice;
	do
	{
		//优化菜单
		printf("\n=====================================\n");
		printf("||          房间价格管理           ||\n");
		printf("=====================================\n");
		printf("|| 1. 单个房间价格调整             ||\n");
		printf("|| 2. 批量房间价格调整             ||\n");
		printf("|| 0. 返回上级菜单                 ||\n");
		printf("=====================================\n");
		printf(">>> 请输入你的选择(0-2) :");
		scanf("%d", &choice);

		switch (choice)
		{
		case 1:
			adjust_single_room_price();
			break;
		case 2:
			batch_adjust_room_price();
			break;
		case 0:
			manage_setting();
			break;
		default:
			printf("无效选择!\n");
		}
	} while (choice != 0);
}

// 单个房间价格调整
void adjust_single_room_price()
{
	int room_id;
	//优化显示
	printf("=====================================\n");
	printf("||          单个房间价格调整       ||\n");
	printf("=====================================\n");
	printf("|| 请输入要调整价格的房间号:");
	scanf("%d", &room_id);
	Room* current = room_lists;
	int find = 0;
	while (current != NULL)
	{
		if (current->room_id == room_id)
		{
			printf("请输入新的房间价格: ");
			scanf("%d", &current->room_price);
			printf("房间价格调整成功！\n");
			find = 1;
			break;
		}
		current = current->next;
	}
	// 将房间信息写入文件
	FILE* fp = fopen(hotel_room, "w");
	if (fp == NULL)
	{
		printf("无法打开文件 \n");
		return;
	}
	Room* temp = room_lists;
	while (temp != NULL)
	{
		fprintf(fp, "%d %s %d %s\n", temp->room_id, temp->room_type, temp->room_price, temp->room_state);
		temp = temp->next;
	}
	fclose(fp);
}

// 批量房间价格调整
void batch_adjust_room_price()
{
	char room_type[100];
	printf("=====================================\n");
	printf("||          批量房间价格调整       ||\n");
	printf("=====================================\n");
	printf("请输入要调整价格的房间类型: ");
	scanf("%s", room_type);
	int new_price;
	printf("请输入新的房间价格: ");
	scanf("%d", &new_price);
	Room* current = room_lists;
	int count = 0;
	while (current != NULL)
	{
		if (strcmp(current->room_type, room_type) == 0)
		{
			current->room_price = new_price;
			count++;
		}
		current = current->next;
	}
	printf("共调整了%d个房间的价格！\n", count);

	// 将房间信息写入文件
	FILE* fp = fopen(hotel_room, "w");
	if (fp == NULL)
	{
		printf("无法打开文件 ！\n");
		return;
	}
	Room* temp = room_lists;
	while (temp != NULL)
	{
		fprintf(fp, "%d %s %d %s\n", temp->room_id, temp->room_type, temp->room_price, temp->room_state);
		temp = temp->next;
	}
	fclose(fp);
}

// 客户折扣管理
void setCustomerDiscount()
{
	int choice;
	do
	{
		printf("\n=====================================\n");
		printf("||          客户折扣管理           ||\n");
		printf("=====================================\n");
		printf("|| 1. 查看当前折扣                 ||\n");
		printf("|| 2. 修改折扣率                   ||\n");
		printf("|| 0. 返回上级菜单                 ||\n");
		printf("=====================================\n");
		printf(">>> 请输入你的选择(0-2) :");
		scanf("%d", &choice);

		switch (choice) {
		case 1:
			display_current_discounts();
			break;
		case 2:
			// 修改折扣率
			modify_discount_rate();
			break;
		case 0:
			manage_setting();
			break;
		default:
			printf("无效选择!\n");
		}
	} while (choice != 0);
}

// 查看当前折扣
void display_current_discounts()
{
	printf("当前折扣率如下:\n");
	printf("普通客户: %.2f\n", discount_rates[0]);
	printf("VIP客户: %.2f\n", discount_rates[1]);
	printf("白金客户: %.2f\n", discount_rates[2]);
	printf("团体客户: %.2f\n", discount_rates[3]);
}

void modify_discount_rate()
{
	printf("\n请选择要修改折扣率的客户身份类型:\n");
	printf("1. 普通客户\n");
	printf("2. VIP客户\n");
	printf("3. 白金客户\n");
	printf("4. 团体客户\n");
	int choice;
	printf(">>> 请输入你的选择(1-4) :");
	scanf("%d", &choice);

	if (choice < 1 || choice > 4)
	{
		printf("无效选择！\n");
		return;
	}

	// 调用更新折扣率函数
	update_discount_rate(choice - 1); // 将用户选择转换为索引（0-3）
}
void update_discount_rate(int type_index)
{
	printf("请输入新的折扣率: ");
	float new_rate;
	scanf("%f", &new_rate);
	if (new_rate >= 0.0 && new_rate <= 1.0)
	{
		discount_rates[type_index] = new_rate;
		printf("折扣率修改成功！\n");

		// 将折扣率写入文件
		FILE* fp = fopen("D:\\Hotel\\Discount.txt", "w");
		if (fp == NULL)
		{
			printf("无法打开文件 D:\\Hotel\\Discount.txt！\n");
			return;
		}
		for (int i = 0; i < 4; i++)
		{
			fprintf(fp, "%.2f\n", discount_rates[i]);
		}
		fclose(fp);
	}
	else
	{
		printf("折扣率无效，请输入0到1之间的值！\n");
	}
}


/*张善杰部分 管理员统计*/
void data_statistics_menu()
{

	printf("\n数据统计与分析\n");
	printf("================\n");
	printf("1. 单一属性统计\n");
	printf("2. 多属性统计\n");
	printf("3. 预设统计\n");
	printf("4. 按条件统计\n");
	printf("0. 返回上级菜单\n");
	printf("================\n");
	int choice;
	printf("请选择操作: ");
	scanf("%d", &choice);

	switch (choice) {
	case 1:
		single_attribute_statistics();
		break;
	case 2:
		multiple_attribute_statistics();
		break;
	case 3:
		preset_statistics();
		break;
	case 4:
		conditional_statistics();
		break;
	case 0:
		menu_Manager();
		break;
	default:
		printf("无效选择!\n");
		data_statistics_menu();
	}
}

void single_attribute_statistics() {
	printf("\n单一属性统计\n");
	printf("================\n");
	printf("1. 查看空房列表\n");
	printf("2. 计算入住率\n");
	printf("3. 房型入住统计\n");
	printf("0. 返回上级菜单\n");
	printf("================\n");
	int choice;
	printf("请选择操作: ");
	scanf("%d", &choice);

	switch (choice) {
	case 1:
		listEmptyRooms();
		break;
	case 2:
		calculateOccupancyRate();
		break;
	case 3:
		calculateRoomTypeOccupancy();
		break;
	case 0:
		data_statistics_menu();
		break;
	default:
		printf("无效选择!\n");
		single_attribute_statistics();
	}
}

void multiple_attribute_statistics() {
	printf("\n多属性统计\n");
	printf("================\n");
	printf("1. 按房间类型和客户姓名统计入住次数\n");
	printf("2. 按入住时间和离开时间统计\n");
	printf("0. 返回上级菜单\n");
	printf("================\n");
	int choice;
	printf("请选择操作: ");
	scanf("%d", &choice);

	switch (choice) {
	case 1:
		count_by_room_type_and_customer_name();
		break;
	case 2:
		count_by_check_in_and_check_out_date(cusdata);
		break;
	case 0:
		data_statistics_menu();
		break;
	default:
		printf("无效选择!\n");
		multiple_attribute_statistics();
	}
}

void preset_statistics() {
	printf("\n预设统计\n");
	printf("================\n");
	printf("1. 统计某段时间内的入住率\n");
	printf("2. 统计某段时间内的预订率\n");
	printf("0. 返回上级菜单\n");
	printf("================\n");
	int choice;
	printf("请选择操作: ");
	scanf("%d", &choice);

	switch (choice) {
	case 1:
		calculate_occupancy_rate_in_period();
		break;
	case 2:
		calculate_booking_rate_in_period();
		break;
	case 0:
		data_statistics_menu();
		break;
	default:
		printf("无效选择!\n");
		preset_statistics();
	}
}

void conditional_statistics() {
	printf("\n按条件统计\n");
	printf("================\n");
	printf("1. 统计某客户在酒店的入住总天数\n");
	printf("2. 统计某段时间内的入住率和预订率\n");
	printf("0. 返回上级菜单\n");
	printf("================\n");
	int choice;
	printf("请选择操作: ");
	scanf("%d", &choice);

	switch (choice) {
	case 1:
		calculate_total_stay_days_for_customer();
		break;
	case 2:
		calculate_occupancy_and_booking_rate_in_period();
		break;
	case 0:
		data_statistics_menu();
		break;
	default:
		printf("无效选择!\n");
		conditional_statistics();
	}
}
// 查看空房列表
void listEmptyRooms() {
	printf("\n当前空房列表:\n");
	printf("ID\t类型\t价格\n");
	printf("-----------------------\n");

	int count = 0;
	Room* current = room_lists;
	while (current != NULL) {
		if (strcmp(current->room_state, "空闲") == 0) {
			printf("%d\t%s\t%d\n", current->room_id, current->room_type, current->room_price);
			count++;
		}
		current = current->next;
	}

	if (count == 0) {
		printf("当前没有空房\n");
	}
	else {
		printf("共有%d间空房\n", count);
	}
}

// 计算入住率
void calculateOccupancyRate() {
	int total_rooms = 0;
	int occupied_rooms = 0;
	Room* current = room_lists;
	while (current != NULL) {
		total_rooms++;
		if (strcmp(current->room_state, "已入住") == 0) {
			occupied_rooms++;
		}
		current = current->next;
	}
	if (total_rooms == 0) {
		printf("没有房间信息！\n");
	}
	else {
		float occupancy_rate = (float)occupied_rooms / total_rooms * 100;
		printf("当前入住率为: %.2f%%\n", occupancy_rate);
	}
}

// 房型入住统计
void calculateRoomTypeOccupancy() {
	int single_count = 0, double_count = 0, triple_count = 0, suite_count = 0;
	Room* current = room_lists;
	while (current != NULL) {
		if (strcmp(current->room_type, "单人间") == 0) {
			single_count++;
		}
		else if (strcmp(current->room_type, "双人间") == 0) {
			double_count++;
		}
		else if (strcmp(current->room_type, "三人间") == 0) {
			triple_count++;
		}
		else if (strcmp(current->room_type, "套房") == 0) {
			suite_count++;
		}
		current = current->next;
	}
	printf("房型入住统计如下:\n");
	printf("单人间: %d\n", single_count);
	printf("双人间: %d\n", double_count);
	printf("三人间: %d\n", triple_count);
	printf("套房: %d\n", suite_count);
}

// 按房间类型统计入住次数
void count_by_room_type() {
	int single = 0, double_ = 0, triple = 0, suite = 0;
	Room* current = room_lists;
	while (current != NULL) {
		if (strcmp(current->room_state, "已入住") == 0) {
			if (strcmp(current->room_type, "单人间") == 0) single++;
			if (strcmp(current->room_type, "双人间") == 0) double_++;
			if (strcmp(current->room_type, "三人间") == 0) triple++;
			if (strcmp(current->room_type, "套房") == 0) suite++;
		}
		current = current->next;
	}
	printf("单人间入住次数: %d\n", single);
	printf("双人间入住次数: %d\n", double_);
	printf("三人间入住次数: %d\n", triple);
	printf("套房入住次数: %d\n", suite);
}

// 按客户姓名统计入住次数
void count_by_customer_name() {
	char customer_name[20];
	printf("请输入客户姓名: ");
	scanf("%s", customer_name);
	int count = 0;
	Room* current = room_lists;
	while (current != NULL) {
		if (strcmp(current->room_state, "已入住") == 0) {
			for (Ord* order = cusdata; order != NULL; order = order->next) {
				if (strcmp(order->customer_name, customer_name) == 0 && order->room_id == current->room_id) {
					count++;
					break;
				}
			}
		}
		current = current->next;
	}
	printf("客户 %s 的入住次数: %d\n", customer_name, count);
}

// 按入住时间统计
void count_by_check_in_date() {
	char start_date[10], end_date[10];
	printf("请输入开始日期: ");
	scanf("%s", start_date);
	printf("请输入结束日期: ");
	scanf("%s", end_date);
	int count = 0;
	for (Ord* order = cusdata->next; order != NULL; order = order->next) {
		if (strcmp(order->order_state, "已入住") == 0 && (order->start_time >= start_date && order->start_time <= end_date)) {
			count++;
		}
	}
	printf("在 %s 到 %s 之间的入住次数: %d\n", start_date, end_date, count);
}

// 按房间类型和客户姓名统计入住次数
void count_by_room_type_and_customer_name() {
	char room_type[100], customer_name[20];
	printf("请输入房间类型: ");
	scanf("%s", room_type);
	printf("请输入客户姓名: ");
	scanf("%s", customer_name);
	int count = 0;
	Room* current = room_lists;
	while (current != NULL) {
		if (strcmp(current->room_type, room_type) == 0) {
			for (Ord* order = cusdata; order != NULL; order = order->next) {
				if (strcmp(order->customer_name, customer_name) == 0 && order->room_id == current->room_id) {
					count++;
					break;
				}
			}
		}
		current = current->next;
	}
	printf("客户 %s 在 %s 类型房间的入住次数: %d\n", customer_name, room_type, count);
}

// 将日期字符串"YYYYMMDDHHMM"转换为天数
int date_to_days(const char* date) {
	int year, month, day;
	sscanf(date, "%4d%2d%2d", &year, &month, &day);
	// 简化的天数计算，不考虑闰年和每月天数不同
	return year * 365 + month * 30 + day;
}

// 计算两个日期之间的天数差
int days_between(const char* start_date, const char* end_date) {
	int day = (atoi)(end_date)-(atoi)(start_date);
	if (day < 0)
	{
		day = 1;
	}
	return day;
}

// 按入住时间和离开时间统计
// 按入住时间和离开时间统计
void count_by_check_in_and_check_out_date(Ord* cusdata) {
	char start_date[15], end_date[15];
	printf("请输入开始日期 (YYYYMMDDHHMM): ");
	scanf("%14s", start_date); // 限制输入长度为14个字符，防止缓冲区溢出
	printf("请输入结束日期 (YYYYMMDDHHMM): ");
	scanf("%14s", end_date);
	int total_days = 0;

	for (Ord* order = cusdata; order != NULL; order = order->next) {
		if (strcmp(order->order_state, "已入住") == 0) {
			// 检查订单的入住时间是否在给定的时间范围内
			if (strcmp(order->start_time, start_date) >= 0 && strcmp(order->end_time, end_date) <= 0) {
				// 计算订单的入住天数
				total_days += days_between(order->start_time, order->end_time) + 1;
			}
		}
	}
	printf("在 %s 到 %s 之间的入住天数: %d\n", start_date, end_date, total_days);
}
// 统计某段时间内的入住率
void calculate_occupancy_rate_in_period() {
	char start_date[13], end_date[13];
	printf("请输入开始日期:");
	scanf("%s", start_date);
	printf("请输入结束日期: ");
	scanf("%s", end_date);
	int total_rooms = 0;
	int occupied_rooms = 0;
	Room* current = room_lists;
	while (current != NULL) {
		total_rooms++;
		if (strcmp(current->room_state, "已入住") == 0) {
			for (Ord* order = cusdata->next; order != NULL; order = order->next) {
				if (order->room_id == current->room_id && (order->start_time >= start_date && order->start_time <= end_date)) {
					occupied_rooms++;
					break;
				}
			}
		}
		current = current->next;
	}
	if (total_rooms == 0) {
		printf("没有房间信息！\n");
	}
	else {
		float occupancy_rate = (float)occupied_rooms / total_rooms * 100;
		printf("在 %s 到 %s 之间的入住率为: %.2f%%\n", start_date, end_date, occupancy_rate);
	}
}

// 统计某段时间内的预订率
void calculate_booking_rate_in_period() {
	char start_date[13], end_date[13];
	printf("请输入开始日期 : ");
	scanf("%s", start_date);
	printf("请输入结束日期: ");
	scanf("%s", end_date);
	int total_orders = 0;
	int booked_orders = 0;
	for (Ord* order = cusdata->next; order != NULL; order = order->next) {
		if ((order->start_time >= start_date && order->start_time <= end_date)) {
			total_orders++;
			if (strcmp(order->order_state, "已预订") == 0) {
				booked_orders++;
			}
		}
	}
	if (total_orders == 0) {
		printf("没有订单信息！\n");
	}
	else {
		float booking_rate = (float)booked_orders / total_orders * 100;
		printf("在 %s 到 %s 之间的预订率为: %.2f%%\n", start_date, end_date, booking_rate);
	}
}

// 统计某客户在酒店的入住总天数
void calculate_total_stay_days_for_customer() {
	char customer_name[20];
	printf("请输入客户姓名: ");
	scanf("%s", customer_name);
	int total_days = 0;
	for (Ord* order = cusdata->next; order != NULL; order = order->next) {
		if (strcmp(order->customer_name, customer_name) == 0) {
			int start = atoi(order->start_time);
			int end = atoi(order->end_time);
			total_days += end - start + 1;
		}
	}
	printf("客户 %s 在酒店的入住总天数: %d\n", customer_name, total_days);
}

// 统计某段时间内的入住率和预订率
void calculate_occupancy_and_booking_rate_in_period() {
	char start_date[13], end_date[13];
	printf("请输入开始日期： ");
	scanf("%s", start_date);
	printf("请输入结束日期: ");
	scanf("%s", end_date);
	int total_rooms = 0;
	int occupied_rooms = 0;
	int total_orders = 0;
	int booked_orders = 0;
	Room* current = room_lists;
	while (current != NULL) {
		total_rooms++;
		if (strcmp(current->room_state, "已入住") == 0) {
			for (Ord* order = cusdata->next; order != NULL; order = order->next) {
				if (order->room_id == current->room_id && (order->start_time >= start_date && order->start_time <= end_date)) {
					occupied_rooms++;
					break;
				}
			}
		}
		current = current->next;
	}
	for (Ord* order = cusdata->next; order != NULL; order = order->next) {
		if ((order->start_time >= start_date && order->start_time <= end_date)) {
			total_orders++;
			if (strcmp(order->order_state, "已预订") == 0) {
				booked_orders++;
			}
		}
	}
	if (total_rooms == 0) {
		printf("没有房间信息！\n");
	}
	else {
		float occupancy_rate = (float)occupied_rooms / total_rooms * 100;
		printf("在 %s 到 %s 之间的入住率为: %.2f%%\n", start_date, end_date, occupancy_rate);
	}
	if (total_orders == 0) {
		printf("没有订单信息！\n");
	}
	else
	{
		float booking_rate = (float)booked_orders / total_orders * 100;
		printf("在 %s 到 %s 之间的预订率为: %.2f%%\n", start_date, end_date, booking_rate);
	}
}

// 4月9日新增信息查询函数
void manager_search_info()
{
	int choice;
	//优化显示
	printf("\n=====================================\n");
	printf("||          信息查询              ||\n");
	printf("=====================================\n");
	printf("|| 1. 查询某客房某时间段是否空    ||\n");
	printf("|| 2. 查询某客人预订信息          ||\n");
	printf("|| 3. 组合查询（某客人某时间段的预订信息） ||\n");
	printf("|| 4. 模糊查询（某客人姓名）      ||\n");
	printf("|| 0. 返回上级菜单                ||\n");
	printf("=====================================\n");
	printf(">>> 请输入你的选择(0-4) :");
	scanf("%d", &choice);

	switch (choice)
	{
	case 0:
		//返回管理员菜单
		manage_setting();
		break;
	case 1: {
		int room_id;
		char start_time[20], end_time[20];
		printf("请输入客房号：");
		scanf("%d", &room_id);
		printf("请输入开始时间（YYYY-MM-DD）：");
		scanf("%s", start_time);
		printf("请输入结束时间（YYYY-MM-DD）：");
		scanf("%s", end_time);

		Ord* temp = cusdata;
		int is_available = 1;
		while (temp != NULL)
		{
			if (temp->room_id == room_id)
			{
				if ((compare_dates(temp->start_time, end_time) < 0) && (compare_dates(temp->end_time, start_time) > 0))
				{
					is_available = 0;
					break;
				}
			}
			temp = temp->next;
		}
		if (is_available)
		{
			printf("该客房在该时间段为空。\n");
		}
		else
		{
			printf("该客房在该时间段已被预订。\n");
		}
		break;
	}
	case 2:
	{
		char customer_name[20];
		printf("请输入客人姓名：");
		scanf("%s", customer_name);

		Ord* temp = cusdata;
		int found = 0;
		while (temp != NULL)
		{
			if (strcmp(temp->customer_name, customer_name) == 0)
			{
				if (!found)
				{
					printf("订单号\t房间号\t房间类型\t房间价格\t订单状态\t客户姓名\t客户电话\t客户身份\t入住时间\t离开时间\n");
				}
				printf("%d\t%d\t%s\t%d\t%s\t%s\t%s\t%s\t%s\t%s\n",
					temp->order_id, temp->room_id, temp->room_type, temp->room_price,
					temp->order_state, temp->customer_name, temp->customer_phone,
					temp->customer_identity, temp->start_time, temp->end_time);
				found = 1;
			}
			temp = temp->next;
		}
		if (!found)
		{
			printf("未找到该客人的预订信息。\n");
		}
		break;
	}
	case 3:
	{
		char customer_name[20];
		char start_time[20], end_time[20];
		printf("请输入客人姓名：");
		scanf("%s", customer_name);
		printf("请输入开始时间（YYYY-MM-DD）：");
		scanf("%s", start_time);
		printf("请输入结束时间（YYYY-MM-DD）：");
		scanf("%s", end_time);

		Ord* temp = cusdata;
		int found = 0;
		while (temp != NULL)
		{
			if (strcmp(temp->customer_name, customer_name) == 0)
			{
				if ((compare_dates(temp->start_time, end_time) < 0) && (compare_dates(temp->end_time, start_time) > 0))
				{
					if (!found)
					{
						printf("订单号\t房间号\t房间类型\t房间价格\t订单状态\t客户姓名\t客户电话\t客户身份\t入住时间\t离开时间\n");
					}
					printf("%d\t%d\t%s\t%d\t%s\t%s\t%s\t%s\t%s\t%s\n",
						temp->order_id, temp->room_id, temp->room_type, temp->room_price,
						temp->order_state, temp->customer_name, temp->customer_phone,
						temp->customer_identity, temp->start_time, temp->end_time);
					found = 1;
				}
			}
			temp = temp->next;
		}
		if (!found)
		{
			printf("未找到该客人在该时间段的预订信息。\n");
		}
		break;
	}
	case 4:
		// 模糊查询
	{
		char customer_name[20];
		printf("请输入客人姓名（模糊查询）：");
		scanf("%s", customer_name);
		Ord* temp = cusdata;
		int found = 0;
		while (temp != NULL)
		{
			if (strstr(temp->customer_name, customer_name) != NULL)
			{
				if (!found)
				{
					printf("订单号\t房间号\t房间类型\t房间价格\t订单状态\t客户姓名\t客户电话\t客户身份\t入住时间\t离开时间\n");
				}
				printf("%d\t%d\t%s\t%d\t%s\t%s\t%s\t%s\t%s\t%s\n",
					temp->order_id, temp->room_id, temp->room_type, temp->room_price,
					temp->order_state, temp->customer_name, temp->customer_phone,
					temp->customer_identity, temp->start_time, temp->end_time);
				found = 1;
			}
			temp = temp->next;
		}
		if (!found)
		{
			printf("未找到相关的预订信息。\n");
		}
		break;
	}
	default:
		printf("无效的选择，请重新输入！\n");
	}
}

